package com.jiuli_travel.travel_service;

import com.alibaba.dashscope.aigc.generation.GenerationOutput;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.jiuli_travel.attraction_service.model.vo.AttractionVO;
import com.jiuli_travel.attraction_service.service.IAttractionService;
import com.jiuli_travel.travel_service.model.vo.ItinerariesVO;
import com.jiuli_travel.travel_service.model.vo.TipsVO;
import com.jiuli_travel.travel_service.service.IItinerariesService;
import com.jiuli_travel.utils.DashScopeApiUtils;
import com.jiuli_travel.utils.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Traveling-Tips")
public class TravelingTips {

    @Autowired
    private IAttractionService attractionService;

    @Autowired
    private IItinerariesService itinerariesService;

    /**
     * 旅行攻略搜索框（可以搜索到攻略，也可以搜素到单个景点）
     */
    @GetMapping("/search")
    public Result search(String searchText){
        // 1. 搜索景点的数据回来
        List<AttractionVO> attractionVOS = attractionService.searchAttraction(searchText);

        // 2. 搜索行程安排的数据回来
        List<ItinerariesVO> itinerariesVOS = itinerariesService.searchItineraries(searchText);

        // 3. 封装数据并返回
        TipsVO tipsVO = new TipsVO();
        tipsVO.setAttractionVOS(attractionVOS);
        tipsVO.setItinerariesVOS(itinerariesVOS);

        // 4. return
        return Result.ok(tipsVO);
    }

    /**
     * 攻略详情
     */
    @GetMapping("/getTravelingTipsDetailInfo")
    public void getTravelingTipsDetailInfo(Long tipId){

    }

    /**
     * 根据AI获取攻略信息
     */
    @GetMapping("/getTravelingTipsByAI")
    @Parameters({
            @Parameter(name = "token",description = "请求token",required = true,in = ParameterIn.HEADER),
    })
    public Result getTravelingTipsByAI(String searchText){
        if(searchText == null || searchText.isEmpty()){
            return Result.fail("输入文本不能为空");
        }
        GenerationResult generationResult = DashScopeApiUtils.doExecute(searchText);
        System.out.println(generationResult);
        GenerationOutput output = generationResult.getOutput();
        return Result.ok(output.getChoices().get(0).getMessage().getContent());
    }

    /**
     * 根据AI获取攻略的内容，解析然后再将整体的数据放回给前端
     */
}









